home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / UI_GEN.HPP < prev    next >
C/C++ Source or Header  |  1993-09-03  |  24KB  |  699 lines

  1. //    Zinc Interface Library - UI_GEN.HPP
  2. //    COPYRIGHT (C) 1990-1993.  All Rights Reserved.
  3. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  4.  
  5. #if !defined(UI_GEN_HPP)
  6. #    define UI_GEN_HPP
  7. #    if !defined(UI_ENV_HPP)
  8. #        include <ui_env.hpp>
  9. #    endif
  10.  
  11. // --- Version 2.0 and 1.0 compatibility ---
  12. #define UI_NUMBER                UI_BIGNUM
  13.  
  14. // --- Conversion hooks for version 2.0 databases ---
  15.  
  16. #if defined(ZIL200_PERSISTENCE)
  17. #include <z_store.hpp>
  18. UI_ZIL200_STORAGE *_v20file = NULL;
  19. #endif
  20.  
  21. // --- basic typedef declarations ---
  22.  
  23. #if !defined(UCHAR)
  24.     typedef unsigned char UCHAR;
  25. #endif
  26. #if !defined(USHORT)
  27.     typedef unsigned short USHORT;
  28. #endif
  29. #if !defined(ULONG)
  30.     typedef unsigned long ULONG;
  31. #endif
  32.  
  33. // --- NULL ---
  34.  
  35. #if defined(NULL)
  36. #undef NULL
  37. #endif
  38. #define    NULL        0
  39. #define NULLP(type)    ((type *)0)
  40. #define NULLF(type)    ((type *)0)
  41.  
  42. // --- TRUE/FALSE ---
  43.  
  44. #if !defined(TRUE)
  45.     const int TRUE = 1;
  46.     const int FALSE = 0;
  47. #endif
  48.  
  49. // --- UIF_FLAGS ---
  50. typedef USHORT UIF_FLAGS;
  51. const UIF_FLAGS UIF_NO_FLAGS            = 0x0000;
  52.  
  53. // --- UIS_STATUS ---
  54. typedef USHORT UIS_STATUS;
  55. const UIS_STATUS UIS_NO_FLAGS            = 0x0000;
  56.  
  57. // --- OBJECTID --- THESE NUMBERS CANNOT BE CHANGED! ---
  58.  
  59. typedef short OBJECTID;
  60. const OBJECTID ID_END                    = -1;    // Special value
  61. const OBJECTID ID_BORDER                = 1;    // Simple objects: 1 through 999
  62. const OBJECTID ID_BUTTON                = 2;
  63. const OBJECTID ID_DATE                    = 3;
  64. const OBJECTID ID_FORMATTED_STRING        = 4;
  65. const OBJECTID ID_ICON                    = 5;
  66. const OBJECTID ID_INTEGER                = 6;
  67. const OBJECTID ID_MAXIMIZE_BUTTON        = 7;
  68. const OBJECTID ID_MINIMIZE_BUTTON        = 8;
  69. const OBJECTID ID_NUMBER                = 9;
  70. const OBJECTID ID_PROMPT                = 11;
  71. const OBJECTID ID_REAL                    = 12;
  72. const OBJECTID ID_STRING                = 13;
  73. const OBJECTID ID_TEXT                    = 15;
  74. const OBJECTID ID_TIME                    = 16;
  75. const OBJECTID ID_TITLE                    = 17;
  76. const OBJECTID ID_WINDOW_OBJECT            = 18;
  77. const OBJECTID ID_POP_UP_ITEM            = 19;
  78. const OBJECTID ID_HELP_CONTEXT            = 20;
  79. const OBJECTID ID_BITMAP_IMAGE            = 21;
  80. const OBJECTID ID_ICON_IMAGE            = 22;
  81. const OBJECTID ID_GROUP                    = 23;
  82. const OBJECTID ID_BIGNUM                = 24;
  83.  
  84. const OBJECTID ID_MATRIX                = 1000;        // Complex objects: 1000 through 1999
  85. const OBJECTID ID_LIST                    = 1001;
  86. const OBJECTID ID_POP_UP_MENU            = 1002;
  87. const OBJECTID ID_PULL_DOWN_ITEM        = 1003;
  88. const OBJECTID ID_PULL_DOWN_MENU        = 1004;
  89. const OBJECTID ID_SCROLL_BAR            = 1005;
  90. const OBJECTID ID_SYSTEM_BUTTON            = 1006;
  91. const OBJECTID ID_WINDOW                = 1007;
  92. const OBJECTID ID_COMBO_BOX                = 1008;
  93. const OBJECTID ID_TOOL_BAR                = 1009;
  94. const OBJECTID ID_VT_LIST                = 1010;
  95. const OBJECTID ID_VLIST                    = 1010;
  96. const OBJECTID ID_HZ_LIST                = 1011;
  97. const OBJECTID ID_HLIST                    = 1011;
  98.  
  99. const OBJECTID ID_DISPLAY                = 2000;        // Special types: 2000 through 2999
  100. const OBJECTID ID_EVENT_MANAGER            = 2001;
  101. const OBJECTID ID_WINDOW_MANAGER        = 2002;
  102. const OBJECTID ID_OUTLINE                = 2100;
  103. const OBJECTID ID_WHITE_SHADOW            = 2101;
  104. const OBJECTID ID_LIGHT_SHADOW            = 2102;
  105. const OBJECTID ID_DARK_SHADOW            = 2103;
  106. const OBJECTID ID_BLACK_SHADOW            = 2104;
  107. const OBJECTID ID_MENU                    = 2105;
  108. const OBJECTID ID_MENU_ITEM                = 2106;
  109. const OBJECTID ID_HOT_KEY                = 2107;
  110.  
  111. // Designer types: 3000 through 3999
  112. const OBJECTID ID_HELPBAR        = 3101;
  113. const OBJECTID ID_VIRTUAL_ELEM   = 3500;
  114.  
  115. // Composite class types: 4000 through 4999
  116.  
  117. // User defined class types: 5000+
  118.  
  119. // --- INFO_REQUEST ---
  120. typedef unsigned INFO_REQUEST;
  121.  
  122. // ----- UI_ELEMENT ---------------------------------------------------------
  123.  
  124. class EXPORT UI_ELEMENT
  125. {
  126.     friend class EXPORT UI_LIST;
  127. public:
  128.     virtual ~UI_ELEMENT(void);
  129.     virtual void *Information(INFO_REQUEST request, void *data, OBJECTID objectID = 0);
  130.     int ListIndex(void);
  131.     UI_ELEMENT *Next(void) { return (next); }
  132.     UI_ELEMENT *Previous(void) { return (previous); }
  133.  
  134. protected:
  135.     UI_ELEMENT *previous, *next;
  136.  
  137.     UI_ELEMENT(void);
  138. };
  139.  
  140. // ----- UI_LIST ------------------------------------------------------------
  141.  
  142. class EXPORT UI_LIST
  143. {
  144.     friend class EXPORT UI_LIST_BLOCK;
  145. public:
  146.     int (*compareFunction)(void *element1, void *element2);
  147.  
  148.     UI_LIST(int (*_compareFunction)(void *element1, void *element2) = NULL);
  149.     virtual ~UI_LIST(void);
  150.     UI_ELEMENT *Add(UI_ELEMENT *newElement);
  151.     UI_ELEMENT *Add(UI_ELEMENT *element, UI_ELEMENT *newElement);
  152.     int Count(void);
  153.     UI_ELEMENT *Current(void) { return (current); }
  154.     virtual void Destroy(void);
  155.     UI_ELEMENT *First(void) { return (first); }
  156.     UI_ELEMENT *Get(int index);
  157.     UI_ELEMENT *Get(int (*findFunction)(void *element1, void *matchData), void *matchData);
  158.     int Index(UI_ELEMENT const *element);
  159.     UI_ELEMENT *Last(void) { return (last); }
  160.     void SetCurrent(UI_ELEMENT *element) { current = element; }
  161.     void Sort(void);
  162.     UI_ELEMENT *Subtract(UI_ELEMENT *element);
  163.     UI_LIST &operator+(UI_ELEMENT *element) { Add(element); return (*this); }
  164.     UI_LIST &operator-(UI_ELEMENT *element) { Subtract(element); return (*this); };
  165.  
  166. protected:
  167.     UI_ELEMENT *first, *last, *current;
  168. };
  169.  
  170. // ----- UI_LIST_BLOCK ------------------------------------------------------
  171.  
  172. class EXPORT UI_LIST_BLOCK : public UI_LIST
  173. {
  174. public:
  175.     virtual ~UI_LIST_BLOCK(void);
  176.     UI_ELEMENT *Add(void);
  177.     UI_ELEMENT *Add(UI_ELEMENT *element);
  178.     int Full(void) { return (freeList.First() ? FALSE : TRUE); }
  179.     UI_ELEMENT *Subtract(UI_ELEMENT *element);
  180.  
  181. protected:
  182.     int noOfElements;
  183.     void *elementArray;
  184.     UI_LIST freeList;
  185.  
  186.     UI_LIST_BLOCK(int noOfElements, int (*compareFunction)(void *element1, void *element2) = NULL);
  187. };
  188.  
  189. // ----- UI_INTERNATIONAL ---------------------------------------------------
  190.  
  191. const int UII_MAXPARAM                = 512;
  192.  
  193. class EXPORT UI_INTERNATIONAL
  194. {
  195.     friend class EXPORT UI_ERROR_SYSTEM;
  196. public:
  197.     static int initialized;
  198. #if defined(ZIL_MSDOS) || defined(ZIL_MSWINDOWS) || defined(ZIL_OS2)
  199.     static int countryCode;
  200. #endif
  201.  
  202.     static char languageName[64];
  203.     static char localeName[64];
  204.     static char decimalSeparator[4];
  205.     static char monDecimalSeparator[4];
  206.     static char thousandsSeparator[4];
  207.     static char monThousandsSeparator[4];
  208.     static char currencySymbol[8];
  209.     static char grouping[10];
  210.     static char monGrouping[10];
  211.     static char intCurrencySymbol[8];
  212.     static int posCurrencyPrecedes;
  213.     static int negCurrencyPrecedes;
  214.     static int fractionDigits;
  215.     static int intFractionDigits;
  216.     static char positiveSign[4];
  217.     static int posSignPrecedes;
  218.     static int posSpaceSeparation;
  219.     static char negativeSign[4];
  220.     static int negSignPrecedes;
  221.     static int negSpaceSeparation;
  222.  
  223.     static int dateFormat;
  224.     static char dateSeparator[4];
  225.  
  226.     static int timeFormat;
  227.     static char timeSeparator[4];
  228.  
  229.     static void Initialize(int forceInitialization = FALSE);
  230.     static int sprintf(char *dst, const char *format, ...);
  231.     static int vsprintf(char *dst, const char *format, void *args);
  232. protected:
  233.     static void rearrangeArgs(const char *format, const void *args,
  234.                    char *newFormat, void *newArgs, void *toRet);
  235. };
  236.  
  237. // ----- UI_BIGNUM ----------------------------------------------------------
  238.  
  239. // --- NMF_FLAGS ---
  240. typedef UIF_FLAGS NMF_FLAGS;
  241. const NMF_FLAGS NMF_NO_FLAGS            = 0x0000;
  242. const NMF_FLAGS NMF_CURRENCY             = 0x0002;
  243. const NMF_FLAGS NMF_CREDIT             = 0x0004;
  244. const NMF_FLAGS NMF_COMMAS             = 0x0008;
  245. const NMF_FLAGS NMF_PERCENT             = 0x0010;
  246. const NMF_FLAGS NMF_SCIENTIFIC             = 0x0020;
  247. const NMF_FLAGS NMF_DECIMAL_FLAGS        = 0xFF00;
  248.  
  249. #define    NMF_DECIMAL(decimal)            (((decimal) + 1) << 8) 
  250. #define    NMF_DIGITS(flags)            ((((flags) >> 8) & 0xFF) - 1)
  251.  
  252. // --- NMI_RESULT ---
  253. enum NMI_RESULT
  254. {
  255.     NMI_OK = 0,                // Number successfully imported.
  256.     NMI_OUT_OF_RANGE,          // Number out of range.
  257.     NMI_INVALID                // Invalid number.
  258. };
  259.  
  260. #define NUMBER_WHOLE    30
  261. #define NUMBER_DECIMAL    8
  262. // Warning, if DIGITS is not 4 or 8, you must rewrite "*" and "/" and "%".
  263. #if defined(ZIL_BITS32)
  264. #define DIGITS        8
  265. #else
  266. #define DIGITS        4
  267. #endif
  268. typedef long   ibignum;
  269. typedef double rbignum;
  270. #if DIGITS == 4
  271. typedef unsigned int nm_number;
  272. #elif DIGITS == 8
  273. typedef unsigned long nm_number;
  274. #endif
  275.  
  276. class EXPORT UI_BIGNUM : public UI_INTERNATIONAL
  277. {
  278.     friend UI_BIGNUM &abs(const UI_BIGNUM &number);
  279.     friend UI_BIGNUM &ceil(const UI_BIGNUM &number) { return number.floor_ceil(0); }
  280.     friend UI_BIGNUM &floor(const UI_BIGNUM &number) { return number.floor_ceil(1); }
  281.     friend UI_BIGNUM &round(const UI_BIGNUM &number, int places = 0);
  282.     friend UI_BIGNUM &truncate(const UI_BIGNUM &number, int places = 0);
  283.  
  284. public:
  285.     UI_BIGNUM(void) { zero(); }
  286.     UI_BIGNUM(ibignum value) { Import(value); }
  287.     UI_BIGNUM(rbignum value) { Import(value); }
  288.     UI_BIGNUM(const char *string) { Import(string, NULLP(const char), NULLP(const char)); }
  289.     UI_BIGNUM(const UI_BIGNUM &number) { *this = number; }
  290.     virtual ~UI_BIGNUM(void) { }
  291.     void Export(ibignum *value);
  292.     void Export(rbignum *value);
  293.     void Export(char *string, NMF_FLAGS nmFlags);
  294.     NMI_RESULT Import(ibignum value);
  295.     NMI_RESULT Import(rbignum value);
  296.     NMI_RESULT Import(const UI_BIGNUM &number);
  297.     NMI_RESULT Import(const char *string, const char *decimalString = NULL,
  298.         const char *signString = NULL);
  299.  
  300.     UI_BIGNUM &operator=(const UI_BIGNUM &number);
  301.     UI_BIGNUM &operator+(const UI_BIGNUM &number);
  302.     UI_BIGNUM &operator-(const UI_BIGNUM &number);
  303.     UI_BIGNUM &operator*(const UI_BIGNUM &number);
  304.     UI_BIGNUM &operator++(void);
  305.     UI_BIGNUM &operator--(void);
  306.     UI_BIGNUM &operator+=(const UI_BIGNUM &number) { return *this = *this + number; }
  307.     UI_BIGNUM &operator-=(const UI_BIGNUM &number) { return *this = *this - number; }
  308.     int operator==(const UI_BIGNUM &number) { return compare(number, FALSE, FALSE, TRUE); }
  309.     int operator!=(const UI_BIGNUM &number) { return compare(number, TRUE, TRUE, FALSE); }
  310.     int operator>(const UI_BIGNUM &number) { return compare(number, TRUE, FALSE, FALSE); }
  311.     int operator>=(const UI_BIGNUM &number) { return compare(number, TRUE, FALSE, TRUE); }
  312.     int operator<(const UI_BIGNUM &number) { return compare(number, FALSE, TRUE, FALSE); }
  313.     int operator<=(const UI_BIGNUM &number) { return compare(number, FALSE, TRUE, TRUE); }
  314.  
  315. private:
  316.     int sign;
  317.     nm_number num[(NUMBER_WHOLE+NUMBER_DECIMAL+DIGITS-1)/DIGITS];
  318.  
  319.     int do_add_loop(const nm_number *aw, int carry);
  320.     void nines_complement(void);
  321.     void zero(void);
  322.     int add_same_sign(const UI_BIGNUM &b, UI_BIGNUM &result);
  323.     int add_diff_sign(const UI_BIGNUM &b, UI_BIGNUM &result);
  324.     UI_BIGNUM &floor_ceil(int sign) const;
  325.     int compare(const UI_BIGNUM &b, int gt, int ls, int eq);
  326.     void checkZero(void);
  327.     void itob(ibignum value);
  328.     void rtob(rbignum value);
  329. };
  330.  
  331. // ----- UI_DATE ------------------------------------------------------------
  332.  
  333. // --- DTF_FLAGS ---
  334. typedef UIF_FLAGS DTF_FLAGS;
  335. const DTF_FLAGS DTF_NO_FLAGS            = 0x0000;
  336. const DTF_FLAGS DTF_US_FORMAT             = 0x0001;
  337. const DTF_FLAGS DTF_EUROPEAN_FORMAT        = 0x0002;
  338. const DTF_FLAGS DTF_JAPANESE_FORMAT        = 0x0004;
  339. const DTF_FLAGS DTF_MILITARY_FORMAT        = 0x0008;
  340. const DTF_FLAGS DTF_DASH                = 0x0010;
  341. const DTF_FLAGS DTF_SLASH                = 0x0020;
  342. const DTF_FLAGS DTF_ALPHA_MONTH            = 0x0040;
  343. const DTF_FLAGS DTF_DAY_OF_WEEK            = 0x0080;
  344. const DTF_FLAGS DTF_UPPER_CASE            = 0x0100;
  345. const DTF_FLAGS DTF_SHORT_YEAR            = 0x0200;
  346. const DTF_FLAGS DTF_SHORT_MONTH            = 0x0400;
  347. const DTF_FLAGS DTF_SHORT_DAY            = 0x0800;
  348. const DTF_FLAGS DTF_ZERO_FILL            = 0x1000;
  349. const DTF_FLAGS DTF_SYSTEM                = 0x4000;
  350.  
  351. // --- DTI_RESULT ---
  352. enum DTI_RESULT
  353. {
  354.     DTI_OK = 0,                // Date successfully imported.
  355.     DTI_INVALID,            // Invalid date value or format.
  356.     DTI_AMBIGUOUS,            // Ambiguous month name.
  357.     DTI_INVALID_NAME,        // Invalid month or day-of-week name.
  358.     DTI_VALUE_MISSING,         // Required date value not present.
  359.     DTI_OUT_OF_RANGE          // Date out of range.
  360. };
  361.  
  362. class EXPORT UI_DATE : public UI_INTERNATIONAL
  363. {
  364. public:
  365.     static char **monthTable;
  366.     static char **dayTable;
  367.  
  368.     UI_DATE(void) { Import(); }
  369.     UI_DATE(const UI_DATE &date) { Import(date); }
  370.     UI_DATE(int year, int month, int day) { Import(year, month, day); }
  371.     UI_DATE(const char *string, DTF_FLAGS dtFlags = DTF_NO_FLAGS) { Import(string, dtFlags); }
  372.     UI_DATE(int packedDate) { Import(packedDate); }
  373.     virtual ~UI_DATE(void) { }
  374.     int DayOfWeek(void);
  375.     int DaysInMonth(void);
  376.     int DaysInYear(void);
  377.     void Export(int *year, int *month, int *day, int *dayOfWeek = NULL);
  378.     void Export(char *string, DTF_FLAGS dtFlags);
  379.     void Export(int *packedDate);
  380.     DTI_RESULT Import(void);
  381.     DTI_RESULT Import(const UI_DATE &date);
  382.     DTI_RESULT Import(int year, int month, int day);
  383.     DTI_RESULT Import(const char *string, DTF_FLAGS dtFlags = DTF_NO_FLAGS);
  384.     DTI_RESULT Import(int packedDate);
  385.  
  386.     long operator=(long days) { value = days; return (value); }
  387.     long operator=(const UI_DATE &date) { value = date.value; return (value); }
  388.     long operator+(long days) { return (value + days); }
  389.     long operator-(long days) { return (value - days); }
  390.     long operator-(const UI_DATE &date) { return (value - date.value); }
  391.     long operator++(void) { value++; return (value); }
  392.     long operator--(void) { value--; return (value); }
  393.     void operator+=(long days) { value += days; }
  394.     void operator-=(long days) { value -= days; }
  395.     int operator==(const UI_DATE& date) { return (value == date.value); }
  396.     int operator!=(const UI_DATE& date) { return (value != date.value); }
  397.     int operator>(const UI_DATE &date) { return (value > date.value); }
  398.     int operator>=(const UI_DATE &date) { return (value >= date.value); }
  399.     int operator<(const UI_DATE &date) { return (value < date.value); }
  400.     int operator<=(const UI_DATE &date) { return (value <= date.value); }
  401.  
  402. private:
  403.     long value;
  404. };
  405.  
  406. // ----- UI_TIME ------------------------------------------------------------
  407.  
  408. // --- TMF_FLAGS ---
  409. typedef UIF_FLAGS TMF_FLAGS;
  410. const TMF_FLAGS TMF_NO_FLAGS            = 0x0000;
  411. const TMF_FLAGS TMF_SECONDS             = 0x0001;
  412. const TMF_FLAGS TMF_HUNDREDTHS            = 0x0002;
  413. const TMF_FLAGS TMF_NO_HOURS            = 0x0004;
  414. const TMF_FLAGS TMF_NO_MINUTES            = 0x0008;
  415. const TMF_FLAGS TMF_TWELVE_HOUR            = 0x0010;
  416. const TMF_FLAGS TMF_TWENTY_FOUR_HOUR    = 0x0020;
  417. const TMF_FLAGS TMF_ZERO_FILL            = 0x0040;
  418. const TMF_FLAGS TMF_COLON_SEPARATOR        = 0x0080;
  419. const TMF_FLAGS TMF_NO_SEPARATOR        = 0x0100;
  420. const TMF_FLAGS TMF_UPPER_CASE            = 0x0200;
  421. const TMF_FLAGS TMF_LOWER_CASE            = 0x0400;
  422. const TMF_FLAGS TMF_SYSTEM                = 0x0800;
  423.  
  424. // --- TMI_RESULT ---
  425. enum TMI_RESULT
  426. {
  427.     TMI_OK = 0,                // Time successfully imported.
  428.     TMI_INVALID,            // Invalid time value or format.
  429.     TMI_OUT_OF_RANGE,        // Time out of range (used by UIW_TIME)
  430.     TMI_VALUE_MISSING        // Required value not present.
  431. };
  432.  
  433. class EXPORT UI_TIME : public UI_INTERNATIONAL
  434. {
  435. public:
  436.     static char *amPtr;
  437.     static char *pmPtr;
  438.  
  439.     UI_TIME(void) { Import(); }
  440.     UI_TIME(const UI_TIME &time) { Import(time); }
  441.     UI_TIME(int hour, int minute, int second = 0, int hundredth = 0) { Import(hour, minute, second, hundredth); }
  442.     UI_TIME(const char *string, TMF_FLAGS tmFlags = TMF_NO_FLAGS) { Import(string, tmFlags); }
  443.     UI_TIME(int packedTime) { Import(packedTime); }
  444.     virtual ~UI_TIME(void) { }
  445.      void Export(int *hour, int *minute, int *second = NULL, int *hundredth = NULL);
  446.     void Export(char *string, TMF_FLAGS tmFlags);
  447.     void Export(int *packedTime);
  448.     TMI_RESULT Import(void);
  449.     TMI_RESULT Import(const UI_TIME &time);
  450.      TMI_RESULT Import(int hour, int minute, int second = 0, int hundredth = 0);
  451.     TMI_RESULT Import(const char *string, TMF_FLAGS tmFlags);
  452.     TMI_RESULT Import(int packedTime);
  453.  
  454.     long operator=(long hundredths) { value = hundredths; return (value); }
  455.     long operator=(const UI_TIME &time) { value = time.value; return (value); }
  456.     long operator+(long hundredths) { return (value + hundredths); }
  457.     long operator+(const UI_TIME &time) { return (value + time.value); }
  458.     long operator-(long hundredths) { return (value - hundredths); }
  459.     long operator-(const UI_TIME &time) { return (value - time.value); }
  460.     long operator++(void) { value++; return (value); }
  461.     long operator--(void) { value--; return (value); }
  462.     void operator+=(long hundredths) { value += hundredths; }
  463.     void operator-=(long hundredths) { value -= hundredths; }
  464.     int operator==(UI_TIME& time) { return (value == time.value); }
  465.     int operator!=(UI_TIME& time) { return (value != time.value); }
  466.     int operator>(UI_TIME& time) { return (value > time.value); }
  467.     int operator>=(UI_TIME& time) { return (value >= time.value); }
  468.     int operator<(UI_TIME& time) { return (value < time.value); }
  469.     int operator<=(UI_TIME& time) { return (value <= time.value); }
  470.  
  471. private:
  472.     long value;
  473. };
  474.  
  475. // ----- UI_PATH_ELEMENT & UI_PATH ------------------------------------------
  476.  
  477. class EXPORT UI_PATH_ELEMENT : public UI_ELEMENT
  478. {
  479. public:
  480.     char *pathName;
  481.  
  482.     UI_PATH_ELEMENT(char *pathName, int length = -1);
  483.     ~UI_PATH_ELEMENT(void);
  484.  
  485.     // List members.
  486.     UI_PATH_ELEMENT *Next(void) { return((UI_PATH_ELEMENT *)next); }
  487.     UI_PATH_ELEMENT *Previous(void) { return((UI_PATH_ELEMENT *)previous); }
  488. };
  489.  
  490. class EXPORT UI_PATH : public UI_LIST
  491. {
  492. public:
  493.     UI_PATH(char *programPath = NULL, int rememberCWD = TRUE);
  494.     ~UI_PATH(void);
  495.     const char *FirstPathName(void)
  496.         { current = first; return (current ? (const char *)Current()->pathName : NULLP(const char)); };
  497.     const char *NextPathName(void)
  498.         { current = current ? Current()->Next() : NULLP(UI_ELEMENT);
  499.           return (current ? Current()->pathName : NULLP(const char)); };
  500.  
  501.     // List members
  502.     UI_PATH_ELEMENT *Current(void) { return((UI_PATH_ELEMENT *)current); }
  503.     UI_PATH_ELEMENT *First(void) { return((UI_PATH_ELEMENT *)first); }
  504.     UI_PATH_ELEMENT *Last(void) { return((UI_PATH_ELEMENT *)last); }
  505. };
  506.  
  507. // ----- UI_STORAGE_OBJECT & UI_STORAGE -------------------------------------
  508.  
  509. // --- UIS_FLAGS ---
  510. typedef UIF_FLAGS UIS_FLAGS;
  511. const UIS_FLAGS UIS_READ            = 0x0001;
  512. const UIS_FLAGS UIS_READWRITE            = 0x0002;
  513. const UIS_FLAGS UIS_CREATE            = 0x0004;
  514. const UIS_FLAGS UIS_OPENCREATE            = 0x0008;
  515. const UIS_FLAGS UIS_TEMPORARY            = 0x0010;
  516.  
  517. typedef USHORT diskAddr;
  518. #define MAX_NAME_LENGTH            64
  519.  
  520. typedef ULONG inum_t;
  521.  
  522. struct EXPORT UI_STATS_INFO
  523. {
  524. public:
  525.     long size;
  526.     long createTime;
  527.     long modifyTime;
  528.     USHORT useCount;
  529.     USHORT revision;
  530.     USHORT countryID;
  531.     inum_t inum;
  532. };
  533.  
  534. class EXPORT UI_STORAGE
  535. {
  536.     friend struct inode;
  537.     friend struct directoryEntry;
  538.     friend struct openFile;
  539.     friend struct superBlock;
  540.     friend struct cacheData;
  541.     friend class EXPORT UI_STORAGE_OBJECT;
  542.     friend class EXPORT UI_STORAGE_SUPPORT;
  543. public:
  544.     static int cacheSize;
  545.     static UI_PATH *searchPath;
  546.     int storageError;
  547.  
  548.     UI_STORAGE(void) { storageError = 0; fd = -1; }
  549.     UI_STORAGE(const char *name, UIS_FLAGS pFlags = UIS_READWRITE);
  550.     ~UI_STORAGE(void);
  551.     static void AppendFullPath(char *fullPath, const char *pathName = NULL,
  552.         const char *fileName = NULL, const char *extension = NULL);
  553.     static void ChangeExtension(char *name, const char *newExtension);
  554.     int ChDir(const char *newName);
  555.     int RenameObject(const char *oldObject, const char *newName);
  556.     int DestroyObject(const char *name);
  557.     char *FindFirstObject(const char *pattern);
  558.     char *FindNextObject(void);
  559.     char *FindFirstID(OBJECTID nObjectID);
  560.     char *FindNextID(void);
  561.     int Flush(void);
  562.     int MkDir(const char *newName);
  563.     int Save(int revisions = 0);
  564.     int SaveAs(const char *newName, int revisions = 0);
  565.     UI_STATS_INFO *Stats(void);
  566.     static void StripFullPath(const char *fullPath, char *pathName = NULL,
  567.         char *fileName = NULL, char *objectName = NULL, char *objectPathName = NULL);
  568.     static int ValidName(const char *name, int createStorage = FALSE);
  569.     int Version(void);
  570.     int RmDir(const char *name);
  571.     void StorageName(char *buff) {     AppendFullPath(buff, pname, fname, NULL); }
  572.     int Link(const char *path1, const char *path2);
  573.  
  574. private:
  575.     int openLen;
  576.     struct openFile *openFiles;
  577.     UI_STORAGE_OBJECT *currentDirectory;
  578.     int fd;
  579.     char pname[MAXPATHLEN + 1];
  580.     char fname[MAXPATHLEN + 1];
  581.     char tname[MAXPATHLEN + 1];
  582.     int firstTime;
  583.     int flags;
  584.     int modified;
  585.     struct superBlock *sb;
  586.     int cacheLen;
  587.     struct cacheData *cd;
  588.     char *cache;
  589.  
  590.     int findSlot(void);
  591.     diskAddr allocData(void);
  592.     void freeData(unsigned int blknum);
  593.     inum_t allocInode(void);
  594.     diskAddr appendInode(inum_t inum);
  595.     int rwInode(inum_t inum, struct inode *ientry, int direction);
  596.     void *readData(diskAddr blknum);
  597.     void writeData(void *data, int modified);
  598.     int checkOpen(inum_t inum);
  599.     UI_STORAGE_OBJECT *walkPath(const char *name, int stripLast);
  600.     void walkPartialPath(const char *pathname,
  601.                  UI_STORAGE_OBJECT **parentdir,
  602.                  const char **filename);
  603.     int deallocateSpace(struct inode *ientry);
  604. };
  605.  
  606. class EXPORT UI_STORAGE_OBJECT
  607. {
  608.     friend struct inode;
  609.     friend struct directoryEntry;
  610.     friend class EXPORT UI_STORAGE;
  611.     friend class EXPORT UI_STORAGE_SUPPORT;
  612. public:
  613.     int objectError;
  614.     OBJECTID objectID;
  615.     char stringID[32];
  616.  
  617.     UI_STORAGE_OBJECT(void);
  618.     UI_STORAGE_OBJECT(UI_STORAGE &file, const char *name,
  619.               OBJECTID nObjectID, UIS_FLAGS pFlags = UIS_READWRITE);
  620.     ~UI_STORAGE_OBJECT(void) { partialDestruct(); }
  621.     void Touch(void);
  622.     UI_STATS_INFO *Stats(void);
  623.     UI_STORAGE *Storage(void) { return file; }
  624.  
  625. #if defined(ZIL_BIGENDIAN)
  626.     int Load(short *value);
  627.     int Load(USHORT *value);
  628.     int Load(long *value);
  629.     int Load(ULONG *value);
  630.     int Store(short value);
  631.     int Store(USHORT value);
  632.     int Store(long value);
  633.     int Store(ULONG value);
  634. #else
  635.     int Load(short *value) { return rwData(value, sizeof(*value), 0); }
  636.     int Load(USHORT *value) { return rwData(value, sizeof(*value), 0); }
  637.     int Load(long *value) { return rwData(value, sizeof(*value), 0); }
  638.     int Load(ULONG *value) { return rwData(value, sizeof(*value), 0); }
  639.     int Store(short value) { return rwData(&value, sizeof(value), 1); }
  640.     int Store(USHORT value) { return rwData(&value, sizeof(value), 1); }
  641.     int Store(long value) { return rwData(&value, sizeof(value), 1); }
  642.     int Store(ULONG value) { return rwData(&value, sizeof(value), 1); }
  643. #endif
  644.     int Load(char *value) { return rwData(value, sizeof(*value), 0); }
  645.     int Load(UCHAR *value) { return rwData(value, sizeof(*value), 0); }
  646.     int Load(void *buff, int size, int length) { return rwData(buff, size*length, 0); }
  647.     int Load(char *string, int length);
  648.     int Load(char **string);
  649.     int Store(char value) { return rwData(&value, sizeof(value), 1); }
  650.     int Store(UCHAR value) { return rwData(&value, sizeof(value), 1); }
  651.     int Store(void *buff, int size, int length) { return rwData(buff, size*length, 1); }
  652.     int Store(const char *string);
  653.  
  654. private:
  655.     UI_STORAGE *file;
  656.     int inodeIndex;
  657.     long position;
  658.     int flags;
  659.     diskAddr *cachedBlknum;
  660.     diskAddr *cachedBlkptr;
  661.  
  662.     int Load(struct directoryEntry *dirent);
  663.     int Store(const struct directoryEntry *dirent);
  664.     int findName(const char *name);
  665.     diskAddr getBlockPtr(diskAddr blknum);
  666.     int rwData(void *buffer, unsigned N, int direction);
  667.     struct openFile *checkObject(void);
  668.     void openTheFile(UI_STORAGE &pfile, struct directoryEntry *dentry,
  669.         struct inode *ientry, int truncate);
  670.     void partialDestruct(void);
  671. };
  672.  
  673. // ----- Other misellaneous definitions -------------------------------------
  674.  
  675. // --- macros, miscellaneous fixups and generic functions ---
  676. // --- macros ---
  677. #define FlagSet(flag1, flag2) ((flag1) & (flag2))
  678. #define FlagsSet(flag1, flag2) (((flag1) & (flag2)) == (flag2))
  679. #define Max(arg1, arg2) (((arg1) > (arg2)) ? (arg1) : (arg2))
  680. #define Min(arg1, arg2) (((arg1) < (arg2)) ? (arg1) : (arg2))
  681. #define Abs(arg) ((arg > 0) ? arg : -arg)
  682.  
  683. extern char * EXPORT ui_strdup(const char *string);    // uses new instead of malloc.
  684. extern int EXPORT ui_strlen(const char *string);    // checks for null.
  685. extern void EXPORT ui_strrepc(char *str, int c, int repc);
  686. extern void EXPORT ui_strstrip(char *string, int c);
  687. extern char * EXPORT ui_itoa(int value, char *string, int radix);
  688. extern int ui_WildStrcmp(char *str, char *pattern);
  689. extern int ui_stricmp(const char *a, const char *b);
  690. extern int ui_strnicmp(const char *a, const char *b, int n);
  691. extern void ui_strupr(char *a);
  692. extern void ui_strlwr(char *a);
  693.  
  694. #if defined(_SUNOS4)
  695.     void *memmove(void *s1, const void *s2, size_t n);
  696. #endif
  697.  
  698. #endif // UI_GEN_HPP
  699.